{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 293,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "itchat has already logged in.\n"
     ]
    }
   ],
   "source": [
    "import itchat\n",
    "# 先登录\n",
    "itchat.login() \n",
    "#关键字实参hotReload取True使得短时间内无需再次扫码登录\n",
    "#itchat.auto_login(hotReload=True)\n",
    "# 获取好友列表\n",
    "friends = itchat.get_friends(update=True)[0:]\n",
    "#print(friends)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-292-61fadd324b78>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdumps\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfriends\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mensure_ascii\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "import json\n",
    "json.dumps(friends[0], ensure_ascii=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取微信好友头像\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "#itchat.search_friends()\n",
    "print('获取微信好友头像')\n",
    "img_dir = './img_%s'%(user)\n",
    "if not os.path.isdir(img_dir):\n",
    "    os.mkdir(img_dir)\n",
    "for friend in itchat.get_friends(update=True)[0:]:\n",
    "    #可以用此句print查看好友的微信名、备注名\n",
    "    img_name = friend['NickName']+\"_\"+friend['RemarkName']\n",
    "    img_content = itchat.get_head_img(userName=friend[\"UserName\"])\n",
    "    img_file = '%s/%s.jpg'%(img_dir, img_name)\n",
    "    print(img_file)\n",
    "    try:\n",
    "        with open(img_file,'wb') as f:\n",
    "            f.write(img_content)\n",
    "    except Exception as e:\n",
    "        print(repr(e))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始读入图像文件\n"
     ]
    },
    {
     "ename": "error",
     "evalue": "C:\\projects\\opencv-python\\opencv\\modules\\imgcodecs\\src\\loadsave.cpp:637: error: (-215) !buf.empty() && buf.isContinuous() in function cv::imdecode_\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31merror\u001b[0m                                     Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-288-46108ea1d96d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0mimg_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mimg_dir\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;34m'\\\\'\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mimg\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m     \u001b[1;31m#img_content = cv2.imread()\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m     \u001b[0mimg_content\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcv2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mimdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfromfile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_file\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muint8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcv2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mIMREAD_UNCHANGED\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      9\u001b[0m     \u001b[1;31m#cv2.imencode('.jpg',img)[1].tofile('C:/测试1.jpg') # 保存\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m     \u001b[1;31m#print('%s\\t%s'%(img_file, img_content.shape))\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31merror\u001b[0m: C:\\projects\\opencv-python\\opencv\\modules\\imgcodecs\\src\\loadsave.cpp:637: error: (-215) !buf.empty() && buf.isContinuous() in function cv::imdecode_\n"
     ]
    }
   ],
   "source": [
    "#微信好友头像爬取及拼接：https://blog.csdn.net/zrp220807/article/details/80455651\n",
    "import cv2\n",
    "print('开始读入图像文件')\n",
    "img_dir = 'img'\n",
    "img_list = os.listdir(img_dir)\n",
    "for img in img_list:\n",
    "    img_file = img_dir + '\\\\' + img\n",
    "    #img_content = cv2.imread()\n",
    "    img_content = cv2.imdecode(np.fromfile(img_file, dtype=np.uint8), cv2.IMREAD_UNCHANGED)\n",
    "    #cv2.imencode('.jpg',img)[1].tofile('C:/测试1.jpg') # 保存\n",
    "    #print('%s\\t%s'%(img_file, img_content.shape))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "图片文件读取异常：./img/张新胜_.jpg\n"
     ]
    },
    {
     "ename": "KeyError",
     "evalue": "'webwx_data_ticket'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-289-898e250ccf03>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     39\u001b[0m \u001b[0mout_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcreateImg\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mimg_dir\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mout_dir\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     40\u001b[0m \u001b[1;31m# 将这张得到的图片发送到你的微信\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 41\u001b[1;33m \u001b[0mitchat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mout_file\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     42\u001b[0m \u001b[1;31m# 当然你也可以将这张得到的图片分享给你的好友\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     43\u001b[0m \u001b[0mitchat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend_image\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mout_file\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtoUserName\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'filehelper'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\messages.py\u001b[0m in \u001b[0;36msend_image\u001b[1;34m(self, fileDir, toUserName, mediaId, file_)\u001b[0m\n\u001b[0;32m    417\u001b[0m         \u001b[0mtoUserName\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstorageClass\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muserName\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    418\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mmediaId\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 419\u001b[1;33m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupload_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfileDir\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0misPicture\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mnot\u001b[0m \u001b[0mfileDir\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'.gif'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfile_\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfile_\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    420\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    421\u001b[0m             \u001b[0mmediaId\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'MediaId'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\messages.py\u001b[0m in \u001b[0;36mupload_file\u001b[1;34m(self, fileDir, isPicture, isVideo, toUserName, file_, preparedFile)\u001b[0m\n\u001b[0;32m    329\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mchunk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mchunks\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    330\u001b[0m         r = upload_chunk_file(self, fileDir, fileSymbol, fileSize,\n\u001b[1;32m--> 331\u001b[1;33m             file_, chunk, chunks, uploadMediaRequest)\n\u001b[0m\u001b[0;32m    332\u001b[0m     \u001b[0mfile_\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    333\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\messages.py\u001b[0m in \u001b[0;36mupload_chunk_file\u001b[1;34m(core, fileDir, fileSymbol, fileSize, file_, chunk, chunks, uploadMediaRequest)\u001b[0m\n\u001b[0;32m    352\u001b[0m         \u001b[1;33m(\u001b[0m\u001b[1;34m'mediatype'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfileSymbol\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    353\u001b[0m         \u001b[1;33m(\u001b[0m\u001b[1;34m'uploadmediarequest'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0muploadMediaRequest\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 354\u001b[1;33m         \u001b[1;33m(\u001b[0m\u001b[1;34m'webwx_data_ticket'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcookiesList\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'webwx_data_ticket'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    355\u001b[0m         \u001b[1;33m(\u001b[0m\u001b[1;34m'pass_ticket'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloginInfo\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'pass_ticket'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    356\u001b[0m         ('filename' , (os.path.basename(fileDir), file_.read(524288), 'application/octet-stream'))])\n",
      "\u001b[1;31mKeyError\u001b[0m: 'webwx_data_ticket'"
     ]
    }
   ],
   "source": [
    "import math\n",
    "#pip install pillow\n",
    "from PIL import Image\n",
    "\n",
    "def createImg(img_dir, out_dir):\n",
    "    # 拼接好友微信头像\n",
    "    x = 0\n",
    "    y = 0\n",
    "    imgs = os.listdir(img_dir)\n",
    "    random.shuffle(imgs)\n",
    "    # 创建640*640的图片用于填充各小图片\n",
    "    newImg = Image.new('RGBA', (640, 640))\n",
    "    # 以640*640来拼接图片，math.sqrt()开平方根计算每张小图片的宽高，\n",
    "    width = int(math.sqrt(640 * 640 / len(imgs)))\n",
    "    # 每行图片数\n",
    "    numLine = int(640 / width)\n",
    "\n",
    "    for i in imgs:\n",
    "        img_file = './%s/%s'%(img_dir, i)\n",
    "        try:\n",
    "            img = Image.open(img_file)\n",
    "        except Exception:\n",
    "            print('图片文件读取异常：%s'%(img_file))\n",
    "            continue\n",
    "        # 缩小图片\n",
    "        img = img.resize((width, width), Image.ANTIALIAS)\n",
    "        # 拼接图片，一行排满，换行拼接\n",
    "        newImg.paste(img, (x * width, y * width))\n",
    "        x += 1\n",
    "        if x >= numLine:\n",
    "            x = 0\n",
    "            y += 1\n",
    "    out_file = '%s/all_%s.png'%(out_dir, user)\n",
    "    newImg.save(out_file)\n",
    "    return out_file\n",
    "\n",
    "# 拼接微信号有头像\n",
    "out_dir = '.'\n",
    "out_file = createImg(img_dir, out_dir)\n",
    "# 将这张得到的图片发送到你的微信\n",
    "itchat.send_image(out_file)\n",
    "# 当然你也可以将这张得到的图片分享给你的好友\n",
    "itchat.send_image(out_file, toUserName='filehelper') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"MemberList\": [], \"UserName\": \"@e232409af346db72d984ee6b497ec2d1\", \"City\": \"海淀\", \"DisplayName\": \"\", \"PYQuanPin\": \"wangqiwen\", \"RemarkPYInitial\": \"\", \"Province\": \"北京\", \"KeyWord\": \"wqw\", \"RemarkName\": \"\", \"PYInitial\": \"WQW\", \"EncryChatRoomId\": \"\", \"Alias\": \"\", \"Signature\": \"自律更自由\", \"NickName\": \"王奇文\", \"RemarkPYQuanPin\": \"\", \"HeadImgUrl\": \"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=661826231&username=@e232409af346db72d984ee6b497ec2d1&skey=@crypt_15c532e6_3e5d4d4ad36d083fb0bbb24401c192dc\", \"UniFriend\": 0, \"Sex\": 1, \"AppAccountFlag\": 0, \"VerifyFlag\": 0, \"ChatRoomId\": 0, \"HideInputBarFlag\": 0, \"AttrStatus\": 33656871, \"SnsFlag\": 17, \"MemberCount\": 0, \"OwnerUin\": 0, \"ContactFlag\": 3, \"Uin\": 965715160, \"StarFriend\": 0, \"Statues\": 0, \"WebWxPluginSwitch\": 0, \"HeadImgFlag\": 1, \"IsOwner\": 0}'"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "import numpy as np\n",
    "np.save('wechat_data.npy', friends)\n",
    "\n",
    "import json\n",
    "#friends[0].keys()\n",
    "json.dumps(friends[0], ensure_ascii=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "男性好友：481, 一共882, 比例 54.54%\n",
      "女性好友：355, 一共882, 比例 40.25%\n",
      "其他：46, 一共882, 比例 5.22%\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'0': ['其他', 46], '1': ['男', 481], '2': ['女', 355]}"
      ]
     },
     "execution_count": 169,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#import urllib3\n",
    "#urllib3.disable_warnings()\n",
    "\n",
    "# 遍历这个列表，列表里第一位是自己，所以从\"自己\"之后开始计算\n",
    "# 初始化计数器，有男有女，当然，有些人是不填的\n",
    "# 1表示男性，2女性\n",
    "sex_dict = {'1':['男',0], '2':['女',0], '0':['其他',0]}\n",
    "for i in friends[1:]:\n",
    "    sex = str(i[\"Sex\"])\n",
    "    sex_dict[sex][1] += 1\n",
    "# 总数算上，好计算比例啊～\n",
    "total = len(friends[1:])\n",
    "male = sex_dict['1'][1] \n",
    "female = sex_dict['2'][1]\n",
    "other = sex_dict['0'][1]\n",
    "# 好了，打印结果\n",
    "print(\"男性好友：%d, 一共%s, 比例 %.2f%%\" % (male, total, float(male) / total * 100))\n",
    "print(u\"女性好友：%d, 一共%s, 比例 %.2f%%\" % (female, total, float(female) / total * 100))\n",
    "print(u\"其他：%d, 一共%s, 比例 %.2f%%\" % (other, total, float(other) / total * 100))\n",
    "sex_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "#print(friends[0].keys())\n",
    "user = friends[0]['NickName']\n",
    "input_format = ['UserName', 'City', 'DisplayName', 'UniFriend', 'OwnerUin', 'MemberList', 'PYQuanPin', 'RemarkPYInitial', 'Uin', 'AppAccountFlag', 'VerifyFlag', 'Province', 'KeyWord', 'RemarkName', 'PYInitial', 'ChatRoomId', u'IsOwner', 'HideInputBarFlag', u'HeadImgFlag', 'EncryChatRoomId', 'AttrStatus', 'SnsFlag', 'MemberCount', u'WebWxPluginSwitch', 'Alias', 'Signature', 'ContactFlag', 'NickName', 'RemarkPYQuanPin', 'HeadImgUrl', 'Sex', 'StarFriend', 'Statues']\n",
    "output_format = ['NickName','Province','City','PYQuanPin','RemarkName','DisplayName','Sex','Signature']\n",
    "out_list = []\n",
    "for item in friends:\n",
    "    #new_item = [item[i] for i in output_format if not isinstance(item[i],'unicode') else item[i].encode('gbk')]\n",
    "    cur_list = []\n",
    "    for i in output_format:\n",
    "        new_value = item[i]\n",
    "        #if isinstance(item[i],unicode):#python2专用\n",
    "        #    new_value = new_value.encode('utf8')\n",
    "        cur_list.append(new_value)\n",
    "    print('\\t'.join([str(i) for i in cur_list]))\n",
    "    out_list.append(cur_list)\n",
    "    #print json.dumps(new_item, ensure_ascii=False)\n",
    "#print json.dumps(friends[:5], ensure_ascii=False)\n",
    "#=======================\n",
    "import pandas as pd\n",
    "dh = pd.DataFrame(out_list, columns=output_format)\n",
    "#out_list\n",
    "#!pip install xlwt\n",
    "dh.to_excel('wechat_data.xls')\n",
    "dh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'1': ['男', 481], '2': ['女', 355], '0': ['其他', 46]}\n",
      "[]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'all': {'其他': 0, '女': 0, '男': 0},\n",
       " 'empty': {'其他': 0, '女': 0, '男': 0},\n",
       " 'not': {'其他': 0, '女': 0, '男': 0}}"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import jieba\n",
    "import re\n",
    "\n",
    "# 地理位置分布\n",
    "location_list = dh.filter(['Province','City']).values\n",
    "location_dict = {}\n",
    "city_dict = {}\n",
    "for i in location_list:\n",
    "    location_dict[i[0]] = location_dict.get(i[0], 0) + 1\n",
    "    city_dict[i[1]] = city_dict.get(i[1], 0) + 1\n",
    "#location_dict\n",
    "#city_dict\n",
    "\n",
    "#jieba自定义词库\n",
    "# ①一个个添加\n",
    "word_seg_list = ['邹市明','不冒不失','大数据','机器学习','星辰大海','本','删人','微信','蝶变','蹉跎']\n",
    "for i in word_seg_list:\n",
    "    jieba.add_word(i) # 添加\n",
    "#jieba.del_word(\"不冒\") # 删除\n",
    "# 直接加载字典文件\n",
    "#格式：一个词占一行；每一行分三部分：词语、词频（可省略）、词性（可省略），用空格隔开，顺序不可颠倒。\n",
    "#file_name 若为路径或二进制方式打开的文件，则文件必须为 UTF-8 编码。\n",
    "#jieba.load_userdict(file_name) \n",
    "# 中文停用词表，下载地址：\n",
    "# ①https://download.csdn.net/download/ybk233/10606306\n",
    "# ②1893个，https://blog.csdn.net/shijiebei2009/article/details/39696571\n",
    "stopword_file = 'stopword_china.txt'\n",
    "stopword_list = [i.strip() for i in open(stopword_file, encoding='utf8')]\n",
    "#stopword_list\n",
    "\n",
    "sign_list = []\n",
    "cut_list = []\n",
    "sign_dict = {'empty':{'男':0, '女':0, '其他':0},\n",
    "             'not':{'男':0, '女':0, '其他':0},\n",
    "             'all':{'男':0, '女':0, '其他':0}}\n",
    "word_dict = {} # 词频记录\n",
    "print(sex_dict)\n",
    "for i in friends:\n",
    "    signature = i[\"Signature\"]\n",
    "    signature.replace(\" \", \"\").replace(\"span\", \"\").replace(\"class\", \"\").replace(\"emoji\", \"\")\n",
    "    #rep = re.compile(\"1f\\d.+\")\n",
    "    rep = re.compile(\"<span.*?>.*?</span>\")\n",
    "    signature = rep.sub(\"\", signature.replace('\\n','|'))\n",
    "    # 当前信息\n",
    "    cur_name = i['NickName']\n",
    "    cur_sex = sex_dict[str(i['Sex'])][0]# 性别\n",
    "    sign_dict['all'][cur_sex] += 1\n",
    "    if signature:\n",
    "        sign_dict['not'][cur_sex] += 1\n",
    "    else:\n",
    "        sign_dict['empty'][cur_sex] += 1\n",
    "        continue\n",
    "    # 当前签名分词\n",
    "    sign_cut = [w for w in jieba.cut(signature)]#, cut_all=True)\n",
    "    for w in sign_cut:\n",
    "        w = w.strip()\n",
    "        if w not in word_dict:\n",
    "            word_dict[w] = {'男':0,'女':0,'其他':0, 'all':0}\n",
    "        word_dict[w][cur_sex] += 1\n",
    "        word_dict[w]['all'] += 1\n",
    "    sign_list.append([signature, cur_sex])\n",
    "    cut_list.extend(sign_cut)\n",
    "    print('[%s]\\t%s\\t%s ==> %s'%( cur_sex, cur_name, signature, '/'.join(sign_cut)))\n",
    "#print(word_dict)\n",
    "word_list = []\n",
    "# 去停用词\n",
    "for w in word_dict:\n",
    "    if not w or w in stopword_list:\n",
    "        #word_dict.pop(w)\n",
    "        continue\n",
    "    word_list.append([w, word_dict[w]])\n",
    "#print(word_list)\n",
    "word_list = sorted(word_list, key=lambda x:x[1]['all'], reverse=True)\n",
    "print(word_list[:10])\n",
    "\n",
    "sign_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min', 'china': '/nbextensions/echarts-countries-js/china', 'wordcloud': '/nbextensions/echarts/echarts-wordcloud.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"0579e52341d741f5a59782c87125455c\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"af82bc714ea34b5db4de83c7657057cb\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"ac4de361a89644f482a4492585cb6e60\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"1309597a7c5b4af2bf6bdf5f39c57fc9\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"034a8d42a3c94f39ae1ae1cfce7f9ac2\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"a0f64693b228475db34871288c764cb2\" style=\"width:800px;height:400px;\"></div>\n",
       "    <div id=\"fc7f1b117eae49d394c6d40e38a07c13\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts', 'china', 'wordcloud'], function(echarts) {\n",
       "        \n",
       "var myChart_0579e52341d741f5a59782c87125455c = echarts.init(document.getElementById('0579e52341d741f5a59782c87125455c'), null, {renderer: 'canvas'});\n",
       "var option_0579e52341d741f5a59782c87125455c = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u7684882\\u5fae\\u4fe1\\u597d\\u53cb\\u6027\\u522b\\u5206\\u5e03\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 2868104,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u767e\\u5206\\u6bd4\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u7537\",\n",
       "                    \"value\": 481\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5973\",\n",
       "                    \"value\": 355\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5176\\u4ed6\",\n",
       "                    \"value\": 46\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"10%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": null,\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"outside\",\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"green\",\n",
       "                        \"fontSize\": 12\n",
       "                    },\n",
       "                    \"formatter\": \"{b}: {d}%\"\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": null,\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#fff\",\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"seriesId\": 2868104\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u7537\",\n",
       "                \"\\u5973\",\n",
       "                \"\\u5176\\u4ed6\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"right\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_0579e52341d741f5a59782c87125455c.setOption(option_0579e52341d741f5a59782c87125455c);\n",
       "\n",
       "\n",
       "var myChart_af82bc714ea34b5db4de83c7657057cb = echarts.init(document.getElementById('af82bc714ea34b5db4de83c7657057cb'), null, {renderer: 'canvas'});\n",
       "var option_af82bc714ea34b5db4de83c7657057cb = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u7684\\u670b\\u53cb\\u662f\\u5426\\u6709\\u7b7e\\u540d(\\u7537\\uff0c\\u5973\\uff0c\\u5176\\u4ed6)\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 5336494,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u7537\\u6027\\u7b7e\\u540d\\u503e\\u5411\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u65e0\",\n",
       "                    \"value\": 0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6709\",\n",
       "                    \"value\": 0\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"5%\",\n",
       "                \"30%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": null,\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"outside\",\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"green\",\n",
       "                        \"fontSize\": 12\n",
       "                    },\n",
       "                    \"formatter\": \"{b}: {d}%\"\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": null,\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#fff\",\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"seriesId\": 5336494\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5973\\u6027\\u7b7e\\u540d\\u503e\\u5411\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u65e0\",\n",
       "                    \"value\": 0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6709\",\n",
       "                    \"value\": 0\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"35%\",\n",
       "                \"60%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": null,\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"outside\",\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"green\",\n",
       "                        \"fontSize\": 12\n",
       "                    },\n",
       "                    \"formatter\": \"{b}: {d}%\"\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": null,\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#fff\",\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"seriesId\": 5336494\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5176\\u4ed6\\u7b7e\\u540d\\u503e\\u5411\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u65e0\",\n",
       "                    \"value\": 0\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6709\",\n",
       "                    \"value\": 0\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"65%\",\n",
       "                \"80%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": null,\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"outside\",\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"green\",\n",
       "                        \"fontSize\": 12\n",
       "                    },\n",
       "                    \"formatter\": \"{b}: {d}%\"\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": null,\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#fff\",\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"seriesId\": 5336494\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u65e0\",\n",
       "                \"\\u6709\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"right\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_af82bc714ea34b5db4de83c7657057cb.setOption(option_af82bc714ea34b5db4de83c7657057cb);\n",
       "\n",
       "\n",
       "var myChart_ac4de361a89644f482a4492585cb6e60 = echarts.init(document.getElementById('ac4de361a89644f482a4492585cb6e60'), null, {renderer: 'canvas'});\n",
       "var option_ac4de361a89644f482a4492585cb6e60 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u7684\\u5fae\\u4fe1\\u597d\\u53cb\\u5730\\u7406\\u5206\\u5e03\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 6460176,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"map\",\n",
       "            \"name\": \"\\u597d\\u53cb\\u4eba\\u6570\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#000\",\n",
       "                        \"fontSize\": 12\n",
       "                    },\n",
       "                    \"formatter\": null\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": null,\n",
       "                    \"textStyle\": {\n",
       "                        \"color\": \"#fff\",\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"mapType\": \"china\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5317\\u4eac\",\n",
       "                    \"value\": 445\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\",\n",
       "                    \"value\": 155\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u897f\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Nevada\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\",\n",
       "                    \"value\": 66\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\",\n",
       "                    \"value\": 31\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Vienna\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"California\",\n",
       "                    \"value\": 11\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\",\n",
       "                    \"value\": 25\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5185\\u8499\\u53e4\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Dubayy\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0a\\u6d77\",\n",
       "                    \"value\": 35\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"NewYork\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Victoria\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Buenos Aires\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\",\n",
       "                    \"value\": 10\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"AD\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9ed1\\u9f99\\u6c5f\",\n",
       "                    \"value\": 6\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Pulau Pinang\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Cork\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u9655\\u897f\",\n",
       "                    \"value\": 5\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Sha Tin\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Groningen\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\",\n",
       "                    \"value\": 6\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d35\\u5dde\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"South Australia\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Faadhippolhu\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"CA\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u798f\\u5efa\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\",\n",
       "                    \"value\": 6\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Berlin\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5929\\u6d25\",\n",
       "                    \"value\": 7\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\",\n",
       "                    \"value\": 4\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Queensland\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\",\n",
       "                    \"value\": 10\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5b89\\u5fbd\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u897f\",\n",
       "                    \"value\": 3\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Saskatchewan\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Western Australia\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u91cd\\u5e86\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Washington\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u897f\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Illinois\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Basel Landschaft\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5409\\u6797\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Poltava\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"New York\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Basel-stadt\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e91\\u5357\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Offaly\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Sai Kung\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Paris\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"England\",\n",
       "                    \"value\": 2\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Utah\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Minnesota\",\n",
       "                    \"value\": 1\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Kuala Lumpur\",\n",
       "                    \"value\": 1\n",
       "                }\n",
       "            ],\n",
       "            \"roam\": true,\n",
       "            \"showLegendSymbol\": true\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u597d\\u53cb\\u4eba\\u6570\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"left\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ],\n",
       "    \"visualMap\": {\n",
       "        \"type\": \"continuous\",\n",
       "        \"min\": 0,\n",
       "        \"max\": 100,\n",
       "        \"text\": [\n",
       "            \"high\",\n",
       "            \"low\"\n",
       "        ],\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#050\"\n",
       "        },\n",
       "        \"inRange\": {\n",
       "            \"color\": [\n",
       "                \"#50a3ba\",\n",
       "                \"#eac763\",\n",
       "                \"#d94e5d\"\n",
       "            ]\n",
       "        },\n",
       "        \"calculable\": true,\n",
       "        \"splitNumber\": 5,\n",
       "        \"dimension\": null,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"left\",\n",
       "        \"top\": \"bottom\",\n",
       "        \"showLabel\": true\n",
       "    }\n",
       "};\n",
       "myChart_ac4de361a89644f482a4492585cb6e60.setOption(option_ac4de361a89644f482a4492585cb6e60);\n",
       "\n",
       "\n",
       "var myChart_1309597a7c5b4af2bf6bdf5f39c57fc9 = echarts.init(document.getElementById('1309597a7c5b4af2bf6bdf5f39c57fc9'), null, {renderer: 'canvas'});\n",
       "var option_1309597a7c5b4af2bf6bdf5f39c57fc9 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u5fae\\u4fe1\\u597d\\u53cb\\u7b7e\\u540d\\u5173\\u952e\\u8bcd-\\u7537\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 3733218,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"name\": \"\\u5173\\u952e\\u8bcd\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                10,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": []\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_1309597a7c5b4af2bf6bdf5f39c57fc9.setOption(option_1309597a7c5b4af2bf6bdf5f39c57fc9);\n",
       "\n",
       "\n",
       "var myChart_034a8d42a3c94f39ae1ae1cfce7f9ac2 = echarts.init(document.getElementById('034a8d42a3c94f39ae1ae1cfce7f9ac2'), null, {renderer: 'canvas'});\n",
       "var option_034a8d42a3c94f39ae1ae1cfce7f9ac2 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u5fae\\u4fe1\\u597d\\u53cb\\u7b7e\\u540d\\u5173\\u952e\\u8bcd-\\u5973\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 3844815,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"name\": \"\\u5173\\u952e\\u8bcd\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                10,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": []\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_034a8d42a3c94f39ae1ae1cfce7f9ac2.setOption(option_034a8d42a3c94f39ae1ae1cfce7f9ac2);\n",
       "\n",
       "\n",
       "var myChart_a0f64693b228475db34871288c764cb2 = echarts.init(document.getElementById('a0f64693b228475db34871288c764cb2'), null, {renderer: 'canvas'});\n",
       "var option_a0f64693b228475db34871288c764cb2 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u5fae\\u4fe1\\u597d\\u53cb\\u7b7e\\u540d\\u5173\\u952e\\u8bcd-\\u5176\\u4ed6\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 7566794,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"name\": \"\\u5173\\u952e\\u8bcd\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                10,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": []\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_a0f64693b228475db34871288c764cb2.setOption(option_a0f64693b228475db34871288c764cb2);\n",
       "\n",
       "\n",
       "var myChart_fc7f1b117eae49d394c6d40e38a07c13 = echarts.init(document.getElementById('fc7f1b117eae49d394c6d40e38a07c13'), null, {renderer: 'canvas'});\n",
       "var option_fc7f1b117eae49d394c6d40e38a07c13 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u738b\\u5947\\u6587\\u5fae\\u4fe1\\u597d\\u53cb\\u7b7e\\u540d\\u5173\\u952e\\u8bcd-\\u6240\\u6709\",\n",
       "            \"subtext\": \"\",\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"#000\",\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"color\": \"#aaa\",\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"magicType\": {\n",
       "                \"show\": true,\n",
       "                \"type\": [\n",
       "                    \"line\",\n",
       "                    \"bar\",\n",
       "                    \"stack\",\n",
       "                    \"tiled\"\n",
       "                ],\n",
       "                \"title\": {\n",
       "                    \"line\": \"\\u6298\\u7ebf\\u56fe\",\n",
       "                    \"bar\": \"\\u67f1\\u72b6\\u56fe\",\n",
       "                    \"stack\": \"\\u5806\\u53e0\",\n",
       "                    \"tiled\": \"\\u5e73\\u94fa\"\n",
       "                }\n",
       "            },\n",
       "            \"dataZoom\": {\n",
       "                \"show\": true,\n",
       "                \"title\": {\n",
       "                    \"zoom\": \"\\u533a\\u57df\\u7f29\\u653e\",\n",
       "                    \"back\": \"\\u7f29\\u653e\\u8fd8\\u539f\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 1405158,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"formatter\": null,\n",
       "        \"textStyle\": {\n",
       "            \"color\": \"#fff\",\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"name\": \"\\u5173\\u952e\\u8bcd\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                10,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": []\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12,\n",
       "                \"color\": \"#333\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"backgroundColor\": \"#fff\",\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_fc7f1b117eae49d394c6d40e38a07c13.setOption(option_fc7f1b117eae49d394c6d40e38a07c13);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "[<pyecharts.charts.pie.Pie at 0x1fee1d870f0>,\n",
       " <pyecharts.charts.pie.Pie at 0x1fee1d87128>,\n",
       " <pyecharts.charts.map.Map at 0x1fee1d87240>,\n",
       " <pyecharts.charts.wordcloud.WordCloud at 0x1fee1d87710>,\n",
       " <pyecharts.charts.wordcloud.WordCloud at 0x1fee1d87748>,\n",
       " <pyecharts.charts.wordcloud.WordCloud at 0x1fee1d877f0>,\n",
       " <pyecharts.charts.wordcloud.WordCloud at 0x1fee1d873c8>]"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyecharts as pe\n",
    "\n",
    "page = pe.Page('签名词云分布')\n",
    "#-------性别分布---------\n",
    "attr = []\n",
    "val = []\n",
    "for _, v in sex_dict.items():\n",
    "    attr.append(v[0])\n",
    "    val.append(v[1])\n",
    "pie = pe.Pie('%s的%s微信好友性别分布'%(user, total), title_pos='center')\n",
    "pie.add('百分比', attr, val, radius=[10,50], \n",
    "        is_label_show=True, legend_orient='vertical',legend_pos='right',\n",
    "       label_text_color='green', is_more_utils=True)#,rosetype=True)\n",
    "page.add(pie)\n",
    "#-------签名习惯-------------\n",
    "attr = ['无', '有']\n",
    "val1 = [sign_dict['empty']['男'], sign_dict['not']['男']]\n",
    "val2 = [sign_dict['empty']['女'], sign_dict['not']['女']]\n",
    "val3 = [sign_dict['empty']['其他'], sign_dict['not']['其他']]\n",
    "pie = pe.Pie('%s的朋友是否有签名(男，女，其他)'%(user), title_pos='center')\n",
    "pie.add('男性签名倾向', attr, val1, radius=[5,30], \n",
    "        is_label_show=True, legend_orient='vertical',legend_pos='right',\n",
    "       label_text_color='green')#,rosetype=True)#is_random=True, \n",
    "pie.add('女性签名倾向', attr, val2, radius=[35,60], \n",
    "        is_label_show=True, legend_orient='vertical',legend_pos='right',\n",
    "        label_text_color='green')#,rosetype=True)\n",
    "pie.add('其他签名倾向', attr, val3, radius=[65,80], \n",
    "        is_label_show=True, legend_orient='vertical',legend_pos='right',\n",
    "       label_text_color='green', is_more_utils=True)#,rosetype=True)\n",
    "page.add(pie)\n",
    "#------------地理位置分布-------\n",
    "#先安装扩展包\n",
    "#pip install echarts-countries-pypkg echarts-china-provinces-pypkg echarts-china-cities-pypkg echarts-china-counties-pypkg echarts-china-misc-pypkg\n",
    "attr = location_dict.keys()\n",
    "value = location_dict.values()\n",
    "#value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]\n",
    "#attr = [\"福建\", \"山东\", \"北京\", \"上海\", \"甘肃\", \"新疆\", \"河南\", \"广西\", \"西藏\"]\n",
    "map = pe.Map(\"%s的微信好友地理分布\"%(user), title_pos='center')#, width=600, height=400\n",
    "map.add(\"好友人数\",attr,value,maptype=\"china\", #world,china\n",
    "    is_visualmap=True,visual_text_color=\"#050\",legend_pos='left', is_more_utils=True)\n",
    "map.render('map_china.html')\n",
    "page.add(map)\n",
    "#-----------词云--------\n",
    "name = [i[0] for i in word_list]\n",
    "value_all = [i[1]['all'] for i in word_list]\n",
    "value_male = [i[1]['男'] for i in word_list]\n",
    "value_female = [i[1]['女'] for i in word_list]\n",
    "value_other = [i[1]['其他'] for i in word_list]\n",
    "wc1 = pe.WordCloud('%s微信好友签名关键词-男'%(user), title_pos='center')\n",
    "wc1.add(\"关键词\", name, value_male, word_size_range=[10, 100], is_more_utils=True)\n",
    "page.add(wc1)\n",
    "wc2 = pe.WordCloud('%s微信好友签名关键词-女'%(user), title_pos='center')\n",
    "wc2.add(\"关键词\", name, value_female, word_size_range=[10, 100], is_more_utils=True)\n",
    "page.add(wc2)\n",
    "wc3 = pe.WordCloud('%s微信好友签名关键词-其他'%(user), title_pos='center')\n",
    "wc3.add(\"关键词\", name, value_other, word_size_range=[10, 100], is_more_utils=True)\n",
    "page.add(wc3)\n",
    "wc4 = pe.WordCloud('%s微信好友签名关键词-所有'%(user), title_pos='center')\n",
    "wc4.add(\"关键词\", name, value_all, word_size_range=[10, 100], is_more_utils=True)\n",
    "page.add(wc4)\n",
    "#---------------------\n",
    "page.render('wechat_%s.html'%(user))\n",
    "page"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# python NLP系列\n",
    "- [python结巴分词、jieba加载停用词表](https://blog.csdn.net/u012052268/article/details/77825981)\n",
    "- 涉及\n",
    "   - 分词\n",
    "   - 词性标注\n",
    "   - 关键词提取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 201,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小明/ 硕士/ 毕业/ 于/ 中国/ 科学/ 学院/ 科学院/ 中国科学院/ 计算/ 计算所/ ，/ 后/ 在/ 日本/ 京都/ 大学/ 日本京都大学/ 深造\n",
      "[('盆友', 1.0), ('电影', 0.9961264494011037)]\n",
      "我, r\n",
      "在, p\n",
      "这里, r\n",
      "看, v\n",
      "电影, n\n",
      "呢, y\n",
      "，, x\n",
      "小, a\n",
      "盆友, n\n",
      "，, x\n",
      "冯小刚, nr\n",
      "和, c\n",
      "李兰, nr\n",
      "去, v\n",
      "哪里, r\n",
      "了, ul\n",
      "啊, y\n",
      "，, x\n",
      "小, a\n",
      "李, nr\n",
      "快, a\n",
      "告诉, v\n",
      "我, r\n"
     ]
    }
   ],
   "source": [
    "#python结巴分词、jieba加载停用词表，https://blog.csdn.net/u012052268/article/details/77825981\n",
    "import jieba.analyse\n",
    "\n",
    "# 创建停用词list\n",
    "def stopwordslist(filepath):\n",
    "    stopwords = [line.strip() for line in open(filepath, 'r', encoding='utf-8', errors='ignore').readlines()]\n",
    "    return stopwords\n",
    "# 分词字典\n",
    "#词典格式和 dict.txt 一样，一个词占一行；\n",
    "#每一行分三部分：词语、词频（可省略）、词性（可省略），用空格隔开，顺序不可颠倒。\n",
    "#file_name 若为路径或二进制方式打开的文件，则文件必须为 UTF-8 编码\n",
    "#jieba.load_userdict(file_name)\n",
    "# 分词\n",
    "seg_list = jieba.cut(\"我来到北京清华大学\", cut_all=True) # 全模式\n",
    "seg_list = jieba.cut(\"我来到北京清华大学\", cut_all=False)# 精确模式（默认）\n",
    "seg_list = jieba.cut_for_search(\"小明硕士毕业于中国科学院计算所，后在日本京都大学深造\")  # 搜索引擎模式\n",
    "print(\"/ \".join(seg_list)) \n",
    "# 第一个参数：待提取关键词的文本\n",
    "# 第二个参数：返回关键词的数量，重要性从高到低排序\n",
    "# 第三个参数：是否同时返回每个关键词的权重\n",
    "# 第四个参数：词性过滤，为空表示不过滤，若提供则仅返回符合词性要求的关键词\n",
    "s = '我在这里看电影呢，小盆友，冯小刚和李兰去哪里了啊，小李快告诉我'\n",
    "keywords = jieba.analyse.extract_tags(s, topK=20, withWeight=True, allowPOS=())\n",
    "keywords = jieba.analyse.textrank(s, topK=20, withWeight=True, allowPOS=('ns', 'n', 'vn', 'v'))\n",
    "print(keywords)\n",
    "\n",
    "# 加载jieba.posseg并取个别名，方便调用\n",
    "import jieba.posseg as pseg\n",
    "words = pseg.cut(s)\n",
    "for word, flag in words:\n",
    "    # 格式化模版并传入参数\n",
    "    print('%s, %s' % (word, flag))\n",
    "#--------------------- \n",
    "#原文：https://blog.csdn.net/u012052268/article/details/77825981 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Getting uuid of QR code.\n",
      "Downloading QR code.\n",
      "Please scan the QR code to log in.\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    379\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.7, use buffering of HTTP responses\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 380\u001b[1;33m                 \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbuffering\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    381\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: getresponse() got an unexpected keyword argument 'buffering'",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-225-c20f2398e315>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     56\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     57\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'__main__'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 58\u001b[1;33m     \u001b[0mitchat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mauto_login\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     59\u001b[0m     \u001b[1;31m# 获取自己的UserName\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     60\u001b[0m     \u001b[1;31m#myUserName = itchat.get_friends(update=True)[0][\"UserName\"]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\register.py\u001b[0m in \u001b[0;36mauto_login\u001b[1;34m(self, hotReload, statusStorageDir, enableCmdQR, picDir, qrCallback, loginCallback, exitCallback)\u001b[0m\n\u001b[0;32m     34\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     35\u001b[0m         self.login(enableCmdQR=enableCmdQR, picDir=picDir, qrCallback=qrCallback,\n\u001b[1;32m---> 36\u001b[1;33m             loginCallback=loginCallback, exitCallback=exitCallback)\n\u001b[0m\u001b[0;32m     37\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     38\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mconfigured_reply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\login.py\u001b[0m in \u001b[0;36mlogin\u001b[1;34m(self, enableCmdQR, picDir, qrCallback, loginCallback, exitCallback)\u001b[0m\n\u001b[0;32m     51\u001b[0m         \u001b[0misLoggedIn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     52\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misLoggedIn\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 53\u001b[1;33m             \u001b[0mstatus\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_login\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     54\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mqrCallback\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'__call__'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     55\u001b[0m                 \u001b[0mqrCallback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0muuid\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0muuid\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstatus\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mqrcode\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mqrStorage\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetvalue\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\itchat\\components\\login.py\u001b[0m in \u001b[0;36mcheck_login\u001b[1;34m(self, uuid)\u001b[0m\n\u001b[0;32m    131\u001b[0m         uuid, int(-localTime / 1579), localTime)\n\u001b[0;32m    132\u001b[0m     \u001b[0mheaders\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m \u001b[1;34m'User-Agent'\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mUSER_AGENT\u001b[0m \u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 133\u001b[1;33m     \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    134\u001b[0m     \u001b[0mregx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mr'window.code=(\\d+)'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    135\u001b[0m     \u001b[0mdata\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mre\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msearch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mregx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(self, url, **kwargs)\u001b[0m\n\u001b[0;32m    519\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    520\u001b[0m         \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'allow_redirects'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 521\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'GET'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    522\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    523\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0moptions\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m    506\u001b[0m         }\n\u001b[0;32m    507\u001b[0m         \u001b[0msend_kwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msettings\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 508\u001b[1;33m         \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0msend_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    509\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    510\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m    616\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    617\u001b[0m         \u001b[1;31m# Send the request\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 618\u001b[1;33m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0madapter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    619\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    620\u001b[0m         \u001b[1;31m# Total elapsed time of the request (approximately)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    438\u001b[0m                     \u001b[0mdecode_content\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    439\u001b[0m                     \u001b[0mretries\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax_retries\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 440\u001b[1;33m                     \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    441\u001b[0m                 )\n\u001b[0;32m    442\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    599\u001b[0m                                                   \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout_obj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    600\u001b[0m                                                   \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 601\u001b[1;33m                                                   chunked=chunked)\n\u001b[0m\u001b[0;32m    602\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    603\u001b[0m             \u001b[1;31m# If we're going to release the connection in ``finally:``, then\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    381\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    382\u001b[0m                 \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 383\u001b[1;33m                     \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    384\u001b[0m                 \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    385\u001b[0m                     \u001b[1;31m# Remove the TypeError from the exception chain in Python 3;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\http\\client.py\u001b[0m in \u001b[0;36mgetresponse\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1329\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1330\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1331\u001b[1;33m                 \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbegin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1332\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mConnectionError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1333\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\http\\client.py\u001b[0m in \u001b[0;36mbegin\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    295\u001b[0m         \u001b[1;31m# read until we get a non-100 response\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    296\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 297\u001b[1;33m             \u001b[0mversion\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreason\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    298\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mstatus\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mCONTINUE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    299\u001b[0m                 \u001b[1;32mbreak\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_read_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    256\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    257\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 258\u001b[1;33m         \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_MAXLINE\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"iso-8859-1\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    259\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0m_MAXLINE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    260\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mLineTooLong\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"status line\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\socket.py\u001b[0m in \u001b[0;36mreadinto\u001b[1;34m(self, b)\u001b[0m\n\u001b[0;32m    584\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    585\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 586\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    587\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    588\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_timeout_occurred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\ssl.py\u001b[0m in \u001b[0;36mrecv_into\u001b[1;34m(self, buffer, nbytes, flags)\u001b[0m\n\u001b[0;32m   1007\u001b[0m                   \u001b[1;34m\"non-zero flags not allowed in calls to recv_into() on %s\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1008\u001b[0m                   self.__class__)\n\u001b[1;32m-> 1009\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1010\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1011\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0msocket\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mflags\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\ssl.py\u001b[0m in \u001b[0;36mread\u001b[1;34m(self, len, buffer)\u001b[0m\n\u001b[0;32m    869\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Read on closed or unwrapped SSL socket.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    870\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 871\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    872\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mSSLError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    873\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m==\u001b[0m \u001b[0mSSL_ERROR_EOF\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msuppress_ragged_eofs\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\program files (x86)\\python\\lib\\ssl.py\u001b[0m in \u001b[0;36mread\u001b[1;34m(self, len, buffer)\u001b[0m\n\u001b[0;32m    629\u001b[0m         \"\"\"\n\u001b[0;32m    630\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mbuffer\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 631\u001b[1;33m             \u001b[0mv\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuffer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    632\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    633\u001b[0m             \u001b[0mv\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sslobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "# 微信机器人\n",
    "# -*- coding=utf-8 -*-\n",
    "import requests\n",
    "import itchat\n",
    "import random\n",
    "# import sys\n",
    "# reload(sys)\n",
    "# sys.setdefaultencoding('utf-8')\n",
    "\n",
    "\n",
    "KEY = '04f44290d4cf462aae8ac563ea7aac16'\n",
    "\n",
    "def get_response(msg):\n",
    "    apiUrl = 'http://www.tuling123.com/openapi/api'\n",
    "    data = {\n",
    "        'key'    : KEY,\n",
    "        'info'   : msg,\n",
    "        'userid' : 'wechat-robot',\n",
    "    }\n",
    "    try:\n",
    "        r = requests.post(apiUrl, data=data).json()\n",
    "        return r.get('text')\n",
    "    except:\n",
    "        return\n",
    "\n",
    "@itchat.msg_register(itchat.content.TEXT)\n",
    "def tuling_reply(msg):\n",
    "    defaultReply = 'I received: ' + msg['Text']\n",
    "    robots=['——By机器人小杨','——By机器人白杨','——By反正不是本人']\n",
    "    robots=['-^-','^-^','~v~']\n",
    "    reply = get_response(msg['Text'])+random.choice(robots)\n",
    "    return reply or defaultReply\n",
    "\n",
    "# 处理群聊消息\n",
    "\"\"\"\n",
    "@itchat.msg_register(itchat.content.TEXT, isGroupChat=True)\n",
    "def text_reply(msg):\n",
    "  if msg['isAt']:\n",
    "    itchat.send(u'@%s\\u2005I received: %s' % (msg['ActualNickName'], msg))\n",
    "\"\"\"\n",
    "# 自动回复\n",
    "# 封装好的装饰器，当接收到的消息是Text，即文字消息\n",
    "\"\"\"\n",
    "@itchat.msg_register('Text')\n",
    "def text_reply(msg):\n",
    "    # 当消息不是由自己发出的时候\n",
    "    if not msg['FromUserName'] == myUserName:\n",
    "        # 发送一条提示给文件助手\n",
    "        itchat.send_msg(u\"[%s]收到好友@%s 的信息：%s\\n\" %\n",
    "                        (time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(msg['CreateTime'])),\n",
    "                         msg['User']['NickName'],\n",
    "                         msg['Text']), 'filehelper')\n",
    "        # 回复给好友\n",
    "        return u'[自动回复]您好，我现在有事不在，一会再和您联系。\\n已经收到您的的信息：%s\\n' % (msg['Text'])\n",
    "\"\"\"\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    itchat.auto_login()\n",
    "    # 获取自己的UserName\n",
    "    #myUserName = itchat.get_friends(update=True)[0][\"UserName\"]\n",
    "    itchat.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-218-8ed428b256e8>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 微信好友检测，看哪些人把你删除了\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mchatroomUserName\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'@1234567'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mfriend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mitchat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_friends\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mitchat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd_member_into_chatroom\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mchatroomUserName\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mfriend\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "# 微信好友检测，看哪些人把你删除了\n",
    "chatroomUserName = '@1234567'\n",
    "friend = itchat.get_friends()[1]\n",
    " \n",
    "r = itchat.add_member_into_chatroom(chatroomUserName, [friend])\n",
    "if r['BaseResponse']['ErrMsg'] == '':\n",
    "    status = r['MemberList'][0]['MemberStatus']\n",
    "    itchat.delete_member_from_chatroom(chatroom['UserName'], [friend])\n",
    "    return { 3: u'该好友已经将你加入黑名单。',\n",
    "        4: u'该好友已经将你删除。', }.get(status,\n",
    "        u'该好友仍旧与你是好友关系。')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "from pyecharts import Geo\n",
    "\n",
    "data = [\n",
    "    (\"海门\", 9),(\"鄂尔多斯\", 12),(\"招远\", 12),(\"舟山\", 12),(\"齐齐哈尔\", 14),(\"盐城\", 15),\n",
    "    (\"赤峰\", 16),(\"青岛\", 18),(\"乳山\", 18),(\"金昌\", 19),(\"泉州\", 21),(\"莱西\", 21),\n",
    "    (\"日照\", 21),(\"胶南\", 22),(\"南通\", 23),(\"拉萨\", 24),(\"云浮\", 24),(\"梅州\", 25),\n",
    "    (\"文登\", 25),(\"上海\", 25),(\"攀枝花\", 25),(\"威海\", 25),(\"承德\", 25),(\"厦门\", 26),\n",
    "    (\"汕尾\", 26),(\"潮州\", 26),(\"丹东\", 27),(\"太仓\", 27),(\"曲靖\", 27),(\"烟台\", 28),\n",
    "    (\"福州\", 29),(\"瓦房店\", 30),(\"即墨\", 30),(\"抚顺\", 31),(\"玉溪\", 31),(\"张家口\", 31),\n",
    "    (\"阳泉\", 31),(\"莱州\", 32),(\"湖州\", 32),(\"汕头\", 32),(\"昆山\", 33),(\"宁波\", 33),\n",
    "    (\"湛江\", 33),(\"揭阳\", 34),(\"荣成\", 34),(\"连云港\", 35),(\"葫芦岛\", 35),(\"常熟\", 36),\n",
    "    (\"东莞\", 36),(\"河源\", 36),(\"淮安\", 36),(\"泰州\", 36),(\"南宁\", 37),(\"营口\", 37),\n",
    "    (\"惠州\", 37),(\"江阴\", 37),(\"蓬莱\", 37),(\"韶关\", 38),(\"嘉峪关\", 38),(\"广州\", 38),\n",
    "    (\"延安\", 38),(\"太原\", 39),(\"清远\", 39),(\"中山\", 39),(\"昆明\", 39),(\"寿光\", 40),\n",
    "    (\"盘锦\", 40),(\"长治\", 41),(\"深圳\", 41),(\"珠海\", 42),(\"宿迁\", 43),(\"咸阳\", 43),\n",
    "    (\"铜川\", 44),(\"平度\", 44),(\"佛山\", 44),(\"海口\", 44),(\"江门\", 45),(\"章丘\", 45),\n",
    "    (\"肇庆\", 46),(\"大连\", 47),(\"临汾\", 47),(\"吴江\", 47),(\"石嘴山\", 49),(\"沈阳\", 50),\n",
    "    (\"苏州\", 50),(\"茂名\", 50),(\"嘉兴\", 51),(\"长春\", 51),(\"胶州\", 52),(\"银川\", 52),\n",
    "    (\"张家港\", 52),(\"三门峡\", 53),(\"锦州\", 54),(\"南昌\", 54),(\"柳州\", 54),(\"三亚\", 54),\n",
    "    (\"自贡\", 56),(\"吉林\", 56),(\"阳江\", 57),(\"泸州\", 57),(\"西宁\", 57),(\"宜宾\", 58),\n",
    "    (\"呼和浩特\", 58),(\"成都\", 58),(\"大同\", 58),(\"镇江\", 59),(\"桂林\", 59),(\"张家界\", 59),\n",
    "    (\"宜兴\", 59),(\"北海\", 60),(\"西安\", 61),(\"金坛\", 62),(\"东营\", 62),(\"牡丹江\", 63),\n",
    "    (\"遵义\", 63),(\"绍兴\", 63),(\"扬州\", 64),(\"常州\", 64),(\"潍坊\", 65),(\"重庆\", 66),\n",
    "    (\"台州\", 67),(\"南京\", 67),(\"滨州\", 70),(\"贵阳\", 71),(\"无锡\", 71),(\"本溪\", 71),\n",
    "    (\"克拉玛依\", 72),(\"渭南\", 72),(\"马鞍山\", 72),(\"宝鸡\", 72),(\"焦作\", 75),(\"句容\", 75),\n",
    "    (\"北京\", 79),(\"徐州\", 79),(\"衡水\", 80),(\"包头\", 80),(\"绵阳\", 80),(\"乌鲁木齐\", 84),\n",
    "    (\"枣庄\", 84),(\"杭州\", 84),(\"淄博\", 85),(\"鞍山\", 86),(\"溧阳\", 86),(\"库尔勒\", 86),\n",
    "    (\"安阳\", 90),(\"开封\", 90),(\"济南\", 92),(\"德阳\", 93),(\"温州\", 95),(\"九江\", 96),\n",
    "    (\"邯郸\", 98),(\"临安\", 99),(\"兰州\", 99),(\"沧州\", 100),(\"临沂\", 103),(\"南充\", 104),\n",
    "    (\"天津\", 105),(\"富阳\", 106),(\"泰安\", 112),(\"诸暨\", 112),(\"郑州\", 113),(\"哈尔滨\", 114),\n",
    "    (\"聊城\", 116),(\"芜湖\", 117),(\"唐山\", 119),(\"平顶山\", 119),(\"邢台\", 119),(\"德州\", 120),\n",
    "    (\"济宁\", 120),(\"荆州\", 127),(\"宜昌\", 130),(\"义乌\", 132),(\"丽水\", 133),(\"洛阳\", 134),\n",
    "    (\"秦皇岛\", 136),(\"株洲\", 143),(\"石家庄\", 147),(\"莱芜\", 148),(\"常德\", 152),(\"保定\", 153),\n",
    "    (\"湘潭\", 154),(\"金华\", 157),(\"岳阳\", 169),(\"长沙\", 175),(\"衢州\", 177),(\"廊坊\", 193),\n",
    "    (\"菏泽\", 194),(\"合肥\", 229),(\"武汉\", 273),(\"大庆\", 279)]\n",
    "#data = city_dict.items()\n",
    "#print(city_dict.items())\n",
    "geo = Geo(\"全国主要城市空气质量\", \"data from pm2.5\", title_color=\"#fff\", title_pos=\"center\",\n",
    "width=1000, height=600, background_color='#404a59')\n",
    "attr, value = geo.cast(data)\n",
    "geo.add(\"\", attr, value, visual_range=[0, 200], visual_text_color=\"#fff\", symbol_size=15, is_visualmap=True)\n",
    "geo.render('geo.html')\n",
    "#geo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h1>Hello, world!</h1>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def bar():\n",
    "    from IPython.display import display, HTML\n",
    "    chart = HTML('<h1>Hello, world!</h1>')\n",
    "    #chart = HTML(content)\n",
    "    # or chart = charts.plot(...)\n",
    "    display(chart)\n",
    "\n",
    "bar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
